import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;

public class GlobalKeyListener implements NativeKeyListener {
	private TheView tv;

	public void nativeKeyPressed(NativeKeyEvent e) {
		//System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
		if(NativeKeyEvent.getKeyText(e.getKeyCode()).equals("F6")) {
			tv.clickBlue();
		}
		if(NativeKeyEvent.getKeyText(e.getKeyCode()).equals("F7")) {
			tv.clickRed();
		}
		if(NativeKeyEvent.getKeyText(e.getKeyCode()).equals("F8")) {
			tv.clickDragon();
		}
		if(NativeKeyEvent.getKeyText(e.getKeyCode()).equals("F9")) {
			tv.clickBaron();
		}
	}

	public void nativeKeyReleased(NativeKeyEvent e) {
	}

	public void nativeKeyTyped(NativeKeyEvent e) {
	}

	public GlobalKeyListener(TheView tv) { 
		this.tv = tv;
		try {
			GlobalScreen.registerNativeHook();
		}
		catch (NativeHookException ex) {
			System.err.println("There was a problem registering the native hook.");
			System.err.println(ex.getMessage());

			System.exit(1);
		}

		//Construct the example object and initialze native hook.
		GlobalScreen.getInstance().addNativeKeyListener(this);
	}
}